﻿using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;

namespace V2TEK.NET.SH.Silverlight.Charts.GanttHelper
{
    public class AbstractTaskEntryRenderer : Control, ITaskEntryRenderer, INotifyPropertyChanged
    {
        public static readonly DependencyProperty DataProperty = DependencyProperty.Register("Data", typeof(ITaskDescriptor), typeof(AbstractTaskEntryRenderer), new PropertyMetadata(new PropertyChangedCallback(DataChanged)));
        public static readonly DependencyProperty SelectedProperty = DependencyProperty.Register("Selected", typeof(bool), typeof(AbstractTaskEntryRenderer), new PropertyMetadata(false));


        protected static void DataChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (d is AbstractTaskEntryRenderer)
            {
                ((AbstractTaskEntryRenderer)d).DataChanged(e.OldValue, e.NewValue);
            }
        }

        protected void DataChanged(object oldValue, object newValue)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs("Data"));
            }
        }

        #region ITaskEntryRenderer Members

        public ITaskDescriptor Data
        {
            get
            {
                return (ITaskDescriptor)GetValue(DataProperty);
            }
            set
            {
                SetValue(DataProperty, value);
            }
        }

        public bool Selected
        {
            get
            {
                return (bool)GetValue(SelectedProperty);
            }
            set
            {
                SetValue(SelectedProperty, value);
            }
        }

        #endregion

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
